package org.neuedu.ssmp.crm.service.impl;

import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper;
import org.neuedu.ssmp.crm.entity.CustomerLevel;
import org.neuedu.ssmp.crm.entity.vo.ResponseEntity;
import org.neuedu.ssmp.crm.mapper.CustomerLevelMapper;
import org.neuedu.ssmp.crm.service.ICustomerLevelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author MoonHolder
 * @since 2019-12-09
 */
@Service
public class CustomerLevelServiceImpl extends ServiceImpl<CustomerLevelMapper, CustomerLevel> implements ICustomerLevelService {

    @Override
    public ResponseEntity addCustomerLevel(CustomerLevel customerLevel) {
        CustomerLevel level = new LambdaQueryChainWrapper<>(baseMapper).eq(CustomerLevel::getName, customerLevel.getName()).one();
        if (Objects.isNull(level)){
            if (baseMapper.insert(customerLevel) != 0) {
                return ResponseEntity.ok("添加成功！");
            }
            return ResponseEntity.error("出错了");
        }
        return ResponseEntity.error("数据已存在，添加失败！");
    }
}
